﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace 反射课程
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Person person = new Person();   
            person.Id = 1;
            person.Write();

            string classPath = "反射课程.Person";
            var obj = Activator.CreateInstance(typeof(Person));
            var t = obj.GetType().GetProperties();


            Assembly assembly = Assembly.LoadFrom("PersonLib.dll");
            var types = assembly.GetTypes();
            foreach ( var type in types )
            {
                var i = type.GetInterface("IDog");
                
            }
            Type dogType =  assembly.GetType("PersonLib.Dog");
            var dog1 = assembly.CreateInstance("PersonLib.Dog");
            var dog2 = Activator.CreateInstance(dogType);
            var methods = dogType.GetMethods(BindingFlags.Instance | BindingFlags.Public);
            var interfaces =  dogType.GetInterface("IDog");
            foreach (var method in methods)
            {
                var attrs = method.GetCustomAttributes();
                if (method.Name == "Write")
                {
                    var r = method.Invoke(dog1, null);
                }

                if(method.Name == "Eat")
                {
                    Object[] objects = new Object[1];
                    objects[0] = "狗粮";
                    method.Invoke(dog1, objects);

                }

                if (method.Name == "Eat2")
                {
                    Object[] objects = new Object[2];
                    objects[0] = "狗粮";
                    objects[1] = "面包";
                    method.Invoke(dog1, objects);

                }
            }


            

            Console.ReadKey();
        }
    }
}
